package com.atguigu01.create.thread;

/**
 * ClassName: EvenNumberTest
 * Package: com.atguigu01.create.thread
 * Description:
 *
 * @Author ZY
 * @Create 14:13
 * @Version 1.0
 */

//    ①创建一个继承于Thread类的子类
class PrintNumber extends Thread {

    //    ②重写Thread类的run()--->将此线程要执行的操作，声明在此方法体中

    @Override
    public void run() {
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + ":" + i);
            }
        }
    }
}

public class EvenNumberTest {
    public static void main(String[] args) {
        //    ③创建当前Thread的子类的对象
        PrintNumber t1 = new PrintNumber();


        //    ④通过对象调用start()
        t1.start();

        //    main()所在的线程执行的操作：
        for (int i = 1; i <= 100; i++) {
            if (i % 2 == 0) {
                System.out.println(Thread.currentThread().getName() + ":" + i + "***********");
            }
        }

    }
}


